#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        vector<int> a;
        int i = 0;
        for (int j = 0; j < pushed.size(); j++)
        {
            a.push_back(pushed[j]);
            while (a.size() && a.back() == popped[i])
            {
                a.pop_back();
                i++;
            }
        }
        if (!a.empty())
        {
            return false;
        }
        return true;
    }
};